package gui._4swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Demo02 {
    public static void main(String[] args) {
        new Demo02Frame();
    }

    static class Demo02Frame extends JFrame{
        public Demo02Frame(){
            setBounds(100, 100, 400, 400);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            //容器
            Container contentPane = this.getContentPane();
            //绝对布局
            contentPane.setLayout(null);
            Button btn1 = new Button("btn1");
            btn1.setBounds(100,100,70,30);
            btn1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new myJDialog();
                }
            });
            contentPane.add(btn1);
            setVisible(true);
        }
    }

    //弹窗属性和frame类似
    static class myJDialog extends JDialog {
        public myJDialog() {
            setVisible(true);
            setBounds(500,500,300,300);
            this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

            //任何组件都需要放到容器当中，否则无效
            Container container = this.getContentPane();
            // container.setLayout(new FlowLayout(FlowLayout.CENTER));

            Label label = new Label("成功弹出弹窗");
            /*
                显示方框状的乱码
                方法一：设置为MS Song字体
                方法二：在运行配置中的VM option添加：-Dfile.encoding=gbk
            */
            label.setFont(new Font("MS Song", Font.PLAIN, 20));
            container.add(label);
        }
    }
}


